<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>
<h1>冒泡排序</h1>
<script>
    //自己写
    var bubble = function(array) {
        for (var j = 0; j < array.length; j++) {
            for (var i = 0; i < array.length; i++) {
                if (array[i] > array[i + 1]) {
                    var temp = array[i];
                    array[i] = array[i + 1];
                    array[i + 1] = temp;
                }
            }
        }
        return array;

    }

    //网上示例
    var bubbleSort=function(arr){
        for(var i=0;i<arr.length-1;i++){
            for(var j=i+1;j<arr.length;j++){
                if(arr[i]>arr[j]){//如果前面的数据比后面的大就交换
                    var temp=arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
                }
            }
        }
        return arr;
    }
//    console.log("The result is:"+bubbleSort(arr));

</script>
</body>
</html>

